import { createRouter, createWebHistory } from 'vue-router';
import type { RouteRecordRaw } from 'vue-router';

const routes: Array<RouteRecordRaw> = [
    {
        path: '/',
        name: 'Home',
        component: () => import('../views/home/index.vue'),
        meta: { title: '首页' }
    },
    {
        path: '/about',
        name: 'About',
        component: () => import('../views/about/index.vue'),
        meta: { title: '关于我们' }
    },
    {
        path: '/products',
        name: 'Products',
        component: () => import('../views/products/index.vue'),
        meta: { title: '产品服务' }
    },
    {
        path: '/products/:id',
        name: 'ProductDetail',
        component: () => import('../views/products/detail.vue'),
        meta: { title: '产品详情' }
    },
    {
        path: '/news',
        name: 'News',
        component: () => import('../views/news/index.vue'),
        meta: { title: '新闻中心' }
    },
    {
        path: '/news/:id',
        name: 'NewsDetail',
        component: () => import('../views/news/detail.vue'),
        meta: { title: '新闻详情' }
    },
    {
        path: '/contact',
        name: 'Contact',
        component: () => import('../views/contact/index.vue'),
        meta: { title: '联系我们' }
    }
];

const router = createRouter({
    history: createWebHistory(),
    routes
});

router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = `${to.meta.title} - 企业网站`;
    }
    next();
});

export default router;
